package us.gaaoc.framework.webapp.backingbeans.clerk;

import java.util.List;
import java.util.Map;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.model.CaseRecordHistory;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * @author hea
 * @date May 3, 2006
 * @version: GAJE 1.5
 * 
 * <!--
 * 		Edited by Brandon Denney
 * 		2008/06/17
 * 		<br/>
 * 		<p>Revised page to work within GAJE 2.0</p>
 * -->
 * 
 */
public class CaseRecordHistoryPage extends BaseBackingBean {

	/* **************** *
	 * Global Variables *
	 * **************** */
	
	/** Serial Version UID */
    private static final long serialVersionUID = -75737421498L;
	private DataModel historyDataTable;

	/**
	 * Default Constructor.
	 */
	public CaseRecordHistoryPage() {
		this.loadData();
	}

	/**
	 * This method loads the data from database
	 */
	@SuppressWarnings("unchecked")
	private void loadData() {
		
		try{
			Map sessionMap = this.getFacesContext().getExternalContext()
					.getSessionMap();
			String caseUuid = (String) sessionMap.get("caseUuid");
			String courtUuid = (String) sessionMap.get("courtUuid");
			List<CaseRecordHistory> historyList = this.getModelFacade()
					.findHistoryByCaseRecordID(caseUuid, courtUuid);
			historyDataTable = new ListDataModel();
			historyDataTable.setWrappedData(historyList);
		} catch (Exception e) {
			back();
		}
	}
	
	/**
	 * Getter for property historyDataTable
	 * @return historyDataTable
	 */
	public DataModel getHistoryDataTable() {
		return historyDataTable;
	}

	/**
	 * Setter for property historyDataTable
	 * @param historyDataTable
	 */
	public void setHistoryDataTable(DataModel historyDataTable) {
		this.historyDataTable = historyDataTable;
	}

	/**
	 * This method navigates user to the previous page
	 * @return String
	 */
	@SuppressWarnings("unchecked")
	public String back() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		String fromPage = (String) sessionMap.get("from");
		sessionMap.remove("from");
		sessionMap.remove("caseUuid");

		if (fromPage.equalsIgnoreCase("ChildEnforcementCaseTypePage")) {
			return "gotoChildEnforcementCaseTypePage";
		} else if (fromPage.equalsIgnoreCase("ReceivedFilingPage")) {
			return "received";
		} else if (fromPage.equalsIgnoreCase("RejectedFilingPage")) {
			return "rejected";
		} else if (fromPage.equalsIgnoreCase("ImportedFilingPage")) {
			return "imported";
		} else if (fromPage.equalsIgnoreCase("DisposedFilingPage")) {
			return "disposed";
		} else if (fromPage.equalsIgnoreCase("ServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("NonServedFilingPage")) {
			return "served";
		} else if (fromPage.equalsIgnoreCase("childSupportTrashCanPage")) {
			return "childSupportTrashCanPage";
		} else if (fromPage.equalsIgnoreCase("main")) {
			return "main";
		}else if (fromPage.equalsIgnoreCase("searchPage")){
            sessionMap.put("from", "clerkMainPage");
            return "searchPage";
		}else
 
			return "main";
	}
}
